package com.hxd.base;

import java.io.Serializable;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;
import com.fasterxml.jackson.annotation.JsonIgnore;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.FieldNameConstants;

import static com.hxd.common.utils.DateUtils.formatDate;

@Data
@FieldNameConstants
public class BaseEntity implements Serializable {

	private static final long serialVersionUID = 1L;
	
	@ApiModelProperty(value = "主键ID")
	@TableId(value = "id",type = IdType.AUTO)
    protected Integer id;
	
	@ApiModelProperty(value = "创建人ID")
	@TableField(fill=FieldFill.INSERT,update="%s")
	private int createId;
		
	@JsonIgnore
	@TableField(fill=FieldFill.INSERT,update="%s")
	private long createTime;
	
	@TableField(exist = false)
	@ApiModelProperty(value = "创建时间")
	private String createTimeFormat;
	
	@JsonIgnore
	@TableField(fill=FieldFill.UPDATE)
    private long updateTime;
	
	@TableField(exist = false)
	@ApiModelProperty(value = "更新时间")
	private String updateTimeFormat;
	
	@JsonIgnore
	@TableLogic
    @TableField(update="%s")
	private Boolean deleteFlag;
	
	@JsonIgnore
	@TableField(exist = false)
	@ApiModelProperty(value = "页数")
	private long pageNum;
	
	@JsonIgnore
	@TableField(exist = false)
	@ApiModelProperty(value = "每页记录数")
	private long pageSize;
	
	protected void setCreateTime(long createTime) {
		this.createTime = createTime;
		this.createTimeFormat = formatDate(createTime);
	}
	
	protected void setUpdateTime(long updateTime) {
		this.updateTime = updateTime;
		this.updateTimeFormat = formatDate(updateTime);
	}
	
}
